package com.aerfazhe.stock.controller;

import com.aerfazhe.stock.pojo.Order;
import com.aerfazhe.stock.service.StockService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author：wk
 * @Create：2022/4/10/11:20
 * @Description：TODO
 * @Version：1.0
 */
@RestController
@RequestMapping("/stock")
public class StockController {

    @Value("${server.port}")
    private String port;

    @Resource
    private StockService stockService;

    @GetMapping("/reduct")
    public String reduct() {
        System.out.println("扣减库存成功！");
        return "扣减库存成功!"+port;
    }

    /**
     * 扣减库存
     * @param order 订单信息
     * @return
     */
    @PostMapping("/reductStock")
    public Map<String,Object> reductStock(@RequestBody Order order){
        return stockService.reductStock(order);
    }

    /**
     * 模拟异常服务
     * @return
     */
    @GetMapping("/reduct2")
    public String reduct2() {
        int a = 1/0;
        System.out.println("扣减库存成功！");
        return "扣减库存成功!"+port;
    }

}
